/********************************************************************
	created:	2011/04/14
	created:	14:4:2011   23:33
	filename: 	d:\Work\Job\trunk\Speed\ProgressItemDelegate.cpp
	file path:	d:\Work\Job\trunk\Speed
	file base:	ProgressItemDelegate
	file ext:	cpp
	author:		liang
	
	purpose:	
*********************************************************************/
#include "ProgressItemDelegate.h"
#include <QApplication>

ProgressItemDelegate::ProgressItemDelegate(QWidget* pParent)
:QStyledItemDelegate(pParent)
{

}

void ProgressItemDelegate::paint(QPainter* pPainter, const QStyleOptionViewItem &option, const QModelIndex& index) const
{
 	if (index.column() == 4) 
	{
 		float progress = index.data().toFloat();
        progress *= 100;
		QStyleOptionProgressBar progressBarOption;
 		progressBarOption.rect = option.rect;
 		progressBarOption.minimum = 0;
 		progressBarOption.maximum = 100;
 		progressBarOption.progress = progress;
 		progressBarOption.text = QString::number(progress) + "%";
 		progressBarOption.textVisible = true;
 
 		QApplication::style()->drawControl(QStyle::CE_ProgressBar,&progressBarOption, pPainter);
 	}
	else
	{
		QStyledItemDelegate::paint(pPainter, option, index);
	}
}

QSize ProgressItemDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
{
	return QStyledItemDelegate::sizeHint(option, index);
}
